<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div id="app">
    <input type="text" v-model="firstname" />
    <input type="text" v-model="lastname" />
    <div>{{allname}}</div>
  </div>
  <script src="./vue.js"></script>
  <script>
    new Vue({
      el: '#app',
      data: {
        firstname: '',
        lastname: '',
        allname: ''
      },
      methods: {},
      directives: {},
      computed: {},
      // 通常 用 computed就够用了， 但是 watch也有自己独特的作用， 比如一个耗时的异步操作
      watch: {  // watch就是监视， 监视和已经存在的data里面的数据
        firstname(newVal, oldVal) {
          this.allname = newVal + this.lastname
        },
        lastname(newVal, oldVal) {
          this.allname = this.firstname + newVal
        }
      }
    })
  </script>
</body>
</html>